﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

using WLMCoreLibrary;
using System.Data;
using System.Data.Odbc;
using System.Web;

namespace SAW_Core
{
    

    public static class FuncionesLocales
    {
        private static bool CheckUserGrant(ref dbConnector ConexionDB)
        {
            if (!HttpContext.Current.IsDebuggingEnabled)
            {
                //Verificando Permisos del usuario y qu exista un usuario logueado
                if (CurrentSystemUser.IdUsuario == 0)
                    return false;
            }
            return true;
        }

        public static void CheckPagePermision(ref dbConnector ConexionDB)
        {
            if (!CheckUserGrant(ref ConexionDB))
            {
                HttpContext.Current.Response.Write("<script>document.location='/login'</script>");
                HttpContext.Current.Response.End();
            }
        }

        public static void ManejarMensaje()
        {
            if (HttpContext.Current.Request.QueryString["mensaje"] != null)
            {
                HttpContext.Current.Response.Write("<script>$(document).ready(function(){MostrarAlerta('" + HttpContext.Current.Request.QueryString["mensaje"] + "+---url');});</script>");
            }
            if (HttpContext.Current.Session["mensaje"] != null)
            {
HttpContext.Current.Response.Write("<script>$(document).ready(function(){MostrarAlerta('" + HttpContext.Current.Session["mensaje"] + "');});</script>");
HttpContext.Current.Session["mensaje"] = null;
            }
        }

        public static void NoCache()
        {
            HttpContext.Current.Response.AddHeader("Expires", " Mon, 26 Jul 1997 05:00:00 GMT");
            HttpContext.Current.Response.AddHeader("Last-Modified", DateTime.UtcNow.ToString());
            HttpContext.Current.Response.AddHeader("Cache-Control", " no-cache, must-revalidate");
            HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
            HttpContext.Current.Response.AddHeader("Content-type", "text");
        }

        
    }




}
